/*
 * Copyright @ 2024 weili23
 * com.example.mythread.a08threadExerciseGift 15:48
 * All right reserved.
 */

package com.example.mythread.a08threadExerciseGift;

/**
 * @desc:
 * @author: weili23
 * @createTime: 2024/10/21 15:48
 * @version: v1.0
 */
public class MyGift extends Thread{
    private static int giftNum = 100;
    private static Object lock = new Object();
    @Override
    public void run() {
        while (true){
            synchronized (Object.class){
                if(giftNum<10){
                    break;
                }else {
                    giftNum--;
                    System.out.println(Thread.currentThread().getName()+"领取了一个礼物，剩余礼物数量："+giftNum);
                }

            }
        }
    }
}
